package com.flying.mongodb;

import com.flying.mongodb.model.Person;
import com.mongodb.client.MongoClients;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;

import static org.springframework.data.mongodb.core.query.Criteria.where;


@Slf4j
public class MongoApp {
    public static void main(String[] args) throws Exception {
        MongoOperations mongoOperations = new MongoTemplate(MongoClients.create(), "database");
        mongoOperations.insert(new Person("Joe", 34));
        mongoOperations.insert(new Person("walker", 46));
        mongoOperations.insert(new Person("walker", 48));
        log.info(mongoOperations.findOne(new Query(where("name").is("Joe")), Person.class).toString());

        mongoOperations.findAndReplace(Query.query(where("name").is("walker")), new Person("zhang", 55));
        mongoOperations.remove
        mongoOperations.dropCollection("person");
    }
}